/*
@STI LICENSE
(C) 2006-2008 Universit�t Innsbruck.

This file is part of myOntology.

myOntologyis free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

myOntologyis distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with myOntology.  If not, see <http://www.gnu.org/licenses/>.

@STI LICENSE */
/**
 * 
 */
package org.myontology.specialpages.dynamic;


import org.apache.log4j.Logger;
import org.myontology.controller.AbstractAction;
import org.myontology.controller.AbstractController;
import org.myontology.controller.AttributeHolder;
import org.myontology.controller.pages.XMLPage;
import org.myontology.specialpages.SpecialPageAction;
import org.myontology.specialpages.SpecialPageHolder;
import org.myontology.specialpages.SpecialPageRegistry;

/**
 * @author <a href="michael.hackl@sti2.at">Michael Hackl</a>
 * Project: Myontology - www.myontology.org
 * STI
 *
 */
public class TestQuery extends AbstractAction {

	private AbstractController controller;
	private SpecialPageRegistry registry;
	private Logger logger;
	
	

	/* (non-Javadoc)
	 * @see org.myontology.controller.Action#execute(org.myontology.controller.AttributeHolder)
	 */

	public void execute(AttributeHolder attributes) {
		String parameter = attributes.getRequestParameter("param1");
		
		String query = attributes.getRequestParameter("input");
		query = Dictionary.replaceTextWithURI(query);
		logger.info("tested query: "+query);
		
		DynamicConfig c = new DynamicConfig("","",query);
		
		try {
			int setSize = Integer.parseInt(parameter);
			c.setSetSize(setSize);
		}catch (Exception e) {
			logger.error("invalid paramter given as param1: "+parameter);
		}
		finally {}
		controller.injectDepencies(c, attributes);
		SpecialPageHolder p =registry.retrieveSpecialPage(c);
		p.init();
		SpecialPageAction.PAGE.setValue(attributes, p);
		SpecialPageAction.PAGE_LABEL.setValue(attributes, "TestResult of the query");
		XMLPage.TARGET_DIV.setValue(attributes, attributes.getRequestParameter("resultDivId"));
	}

}
